home *** CD-ROM | disk | FTP | other *** search
- Path: kbad.eglin.af.mil!rpi!not-for-mail
- From: liuh2@vccsouth02.its.rpi.edu (nemish)
- Newsgroups: comp.lang.c++
- Subject: How does this look()()()()()?
- Date: 27 Mar 1996 15:11:09 -0500
- Organization: Rensselaer Polytechnic Institute
- Message-ID: <4jc7ct$4od@vccsouth02.its.rpi.edu>
- NNTP-Posting-Host: vccsouth02.its.rpi.edu
-
- Hi,
-
- We use to have a convient way to assign values to an
- array in good ol' C like this.
-
- int vec[10] = {1,2,3,4,5,6,7,8,9,10};
-
- Now, in C++ this kind of style is not encouraged(BTW, is this legal?)
- So we have to do something like.
- vec[0] = 1;
- vec[1] = 2;
- vec[2] = 3;
- .
- .
- .
- vec[9] = 10;
-
- which is a lot of typing.
-
- I just had an idea that we can do something like this,
-
- vec(1)(2)(3)(4)(5)(6)(7)(8)(9)(10);
-
- I wrote a simple program here with STL
-
- #include <vector.h>
- #include <algo.h>
-
- class my_vector:public vector<int> {
- public:
- my_vector():vector<int>() {}
-
- my_vector& operator () (int element) {push_back(element); return (*this);}
- };
-
- int main()
- {
- my_vector vec;
- ostream_iterator<int> out(cout, " ");
-
- vec(1)(2)(3)(4)(5)(6)(7)(8)(9)(10);
- copy(vec.begin(),vec.end(),out);
-
- return 0;
- }
-
- =========================================
-
- What do you guys think? Is there anything that is not appropriate, or
- I am doing something unnecessary or very wrong?
-
- Hsi-Wen Liu
- liuh2@rpi.edu
-